<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
use Spatie\Permission\Models\Permission;


class CheckLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(Session::get('admin.username') && Session::get('admin.id')) {
            /*$route = str_replace('admin/', '', $request->path());
            if (Auth::user()->can($route)){
                return $next($request);
            }else{
                return view('404');
            }*/
            return $next($request);
        }
        die("<script>window.parent.location.href='/admin/login'</script>");
//        return redirect(url('admin/login'));
    }
}
